@extends('Home.User.Common.layout')
@section('title')
    薪酬管理_人事管理
@endsection
@section('content')
    <!--  content  -->
    <main class="common_content">
        <div class="container">
            <div class="ct_main">
                @include('Home.User.Hr.Common.hr_menu')
                <ul class="nav-items1 nav-items2 w999" id="tab-content2">
                    <!--薪酬管理-->
                    <li class="basic-sets active">
                        <form class="selector-head layui-form" method="post" action="{{route('hr_salary')}}">
                            @csrf
                            <h2>薪酬管理</h2>
                            <div class="rt">
                                @if (Auth::user()->hasAnyRole(['admin','leader']))
                                    <div class="layui-input-inline" style="width: 150px;margin-right: 2px;vertical-align: unset;">
                                        <select name="uid" lay-search>
                                            <option value="0" @if(0 == $uid) selected @endif>全员</option>
                                            @foreach($user as $item)
                                                <option value="{{$item->id}}" @if($item->id == $uid) selected @endif>{{$item->username}}</option>
                                            @endforeach
                                        </select>
                                    </div>
                                @endif
                                <table class="date-picker">
                                    <thead>
                                    <tr>
                                        <th>
                                            <input type="text" placeholder="起始日期" class="span2" value="{{$between?$between[0]:''}}" name="date1" id="date1">
                                        </th>
                                        <th>
                                            <input type="text" placeholder="截止日期" class="span2" value="{{$between?$between[1]:''}}" name="date2" id="date2">
                                        </th>
                                    </tr>
                                    </thead>
                                </table>
                                <button class="layui-btn layui-btn-sm" lay-submit lay-filter="formSub"><i class="icon icon-search"></i></button>
                                @if (Auth::user()->hasRole('admin'))
                                    <a href="javacsript:;" class="add-new-btn" title="添加薪酬" onclick="open_button('{{route('salary_add')}}','添加薪酬','1200')"><i class="icon icon-xinzen"></i></a>
                                @endif
                            </div>
                        </form>
                        <div class="layui-form basic-sets-ul">
                            <table class="layui-table">
                                <thead>
                                <tr>
                                    <th>姓名</th>
                                    <th>薪资月份</th>
                                    <th>当前职级</th>
                                    <th>当前基本工资</th>
                                    <th>KPI结果</th>
                                    <th>KPI奖金</th>
                                    <th>KPI提成(业务)</th>
                                    <th>薪资加项</th>
                                    <th>薪资扣款</th>
                                    <th>月薪总额</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                    @foreach($list as $item)
                                        <tr>
                                            <td data-label="姓名"> {{$item->user_name}} </td>
                                            <td data-label="薪资月份"> {{$item->month}}</td>
                                            <td data-label="当前职级"> {{$item->rank}}  </td>
                                            <td data-label="当前基本工资"> {{$item->salary}}  </td>
                                            <td data-label="KPI结果"> {{$item->kpi_result}} </td>
                                            <td data-label="KPI奖金"> {{$item->kpi_bonus}} </td>
                                            <td data-label="KPI提成(业务)"> {{$item->kpi_money}} </td>
                                            <td data-label="薪资加项"> {{$item->add_total}} </td>
                                            <td data-label="薪资扣款"> {{$item->cut_total}} </td>
                                            <td data-label="月薪总额"> {{$item->total}} </td>
                                            <td data-label="操作" class="tac layui-row layui-col-space10">
                                                <a href="javascript:;" class="edit-btn edit-client" onclick="open_button('{{route('salary_edit',$item->id)}}','查看/编辑','1200')" title="查看/编辑"><i class="layui-icon">&#xe642;</i></a>
                                                @if (Auth::user()->id == $admin)
                                                    <a href="javascript:;" class="edit-btn add-schedule" onclick="del('{{route('salary_del',$item->id)}}')" title="删除"><i class="layui-icon">&#xe640;</i></a>
                                                @endif
                                            </td>
                                        </tr>
                                    @endforeach
                                </tbody>
                            </table>
                            <!-- 分页 s -->
                            @if($num>1)
                                <div class="news-pager">
                                    <ul class="pagination" id="page">
                                    </ul>
                                    <div class="pageJump">
                                        <span>跳转到</span>
                                        <input type="text"/>
                                        <span>页</span>
                                        <button type="button" class="button">确定</button>
                                    </div>
                                </div>
                            @endif
                            <!-- 分页 e -->
                        </div>
                    </li>
                </ul>
            </div>
        </div>
    </main>
@endsection
@section('footer')
    <script>
    layui.use(['laydate','form'], function(){
        var laydate = layui.laydate;
        var form = layui.form;

        //执行一个laydate实例
        laydate.render({
            elem: '#date1', //指定元素
            type: 'month'
        });

        //执行一个laydate实例
        laydate.render({
            elem: '#date2', //指定元素
            type: 'month'
        });

        //监听提交
        form.on('submit(formSub)', function(data){
            if (data.field.date1.length<=0){
                layer.msg('起始日期必填',{icon:2});
                return false;
            }else if (data.field.date2.length<=0){
                layer.msg('截止日期必填',{icon:2});
                return false;
            }
        });
    });
    /*删除*/
    function del(url) {
        layer.confirm("你确定要删除吗？此操作不能撤销！", {icon: 3, title:'提示'},
                function(index){//确定回调
                    $.ajax({
                        type: 'get',
                        url: url,
                        dataType: 'json',
                        success: function(data){
                            if(data.code){
                                window.location.reload();
                                layer.close(index);
                            }else{
                                layer.msg(data.msg,{icon: 5,time:1000});
                            }
                        },
                        error:function() {
                            layer.msg('服务器错误!',{icon: 5,time:1000});
                        }
                    });
                },function (index) {//取消回调
                    layer.close(index);
                }
        );
    }
    /***  分页 JS  ***/
    Page({
        num: '{{$num}}',		//页码数
        startnum: '{{$page}}',				//指定页码
        elem:$('#page'),		//指定的元素
        callback:function(n){	//回调函数
            @if($between)
                window.location.href = '{{route('hr_salary')}}?page='+n+'&date1={{$between[0]}}&date2={{$between[1]}}';
            @else
                window.location.href = '{{route('hr_salary')}}?page='+n;
            @endif
        }
    });

</script>
@endsection